package com.bocai.freeman.view.activitys;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.bocai.freeman.R;
import com.bocai.freeman.base.BaseActivity;
import com.bocai.freeman.pickview.TimePickView;
import com.bocai.freeman.utils.ToolbarHelper;

import java.util.Calendar;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2016/5/25.
 */
public class EditAgeActivity extends BaseActivity {

    @Bind(R.id.toolbar)
    Toolbar mToolbar;
    @Bind(R.id.tv_age)
    TextView mTvAge;
    @Bind(R.id.rl_age)
    RelativeLayout mRlAge;

//    private TimePickerView
    private TimePickView mPickerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_age);
        ButterKnife.bind(this);
        initEvent();
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        ToolbarHelper.setup(this, R.string.modify_age, R.mipmap.left_return);
        mToolbar.setOnMenuItemClickListener(item -> {
            // TODO: 2016/5/20 save modify infomation
            return true;
        });

        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        mPickerView = new TimePickView(this, TimePickerView.Type.YEAR_MONTH_DAY);
//        mPickerView.setRange(1960,year);
        mPickerView.setCyclic(false);
        mPickerView.setOnTimeSelectListener(date -> {
            // TODO: 2016/5/25 判断多少岁
        });

        click(mRlAge).subscribe(o -> {
            mPickerView.show();
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_save,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public void onBackPressed() {
        if(mPickerView!=null && mPickerView.isShowing()){
            mPickerView.dismiss();
        }else {
            super.onBackPressed();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }
}
